<?php

namespace App\Admin\Controllers;

use Encore\Admin\Form;
use Encore\Admin\Grid;
use App\Models\TestTopic;
use App\Models\TestQuestion;

use Encore\Admin\Controllers\AdminController;

class TestQuestionsController extends AdminController
{
    protected $title = '小测试问题';

    protected function grid()
    {
        $grid = new Grid(new TestQuestion());
        $grid->model()->orderBy('id');

        $grid->column('id', 'ID');
        
        $grid->column('topic_id', '关联题目')->display(function () {
            return $this->topic ? $this->topic->title : '';
        });

        $grid->column('question', '问题');
        $grid->column('question_option', '问题选项');
        

        $grid->disableRowSelector();
        $grid->disableColumnSelector();
        $grid->disableExport();
        $this->gridActions($grid);

        return $grid;
    }

	protected function gridActions(Grid $grid)
	{
		$grid->actions(function (Grid\Displayers\Actions $actions) {
			$actions->disableView();
			$actions->disableDelete();
		});
	}

     protected function form()
    {
        $form = new Form(new TestQuestion());

        $form->select('topic_id', '关联题目')->options(TestTopic::all()->pluck('title','id'))
            ->rules('required');
        $form->text('question','问题')->rules('required');
        $form->select('question_option', '答案')->options(config('site.answer'))
            ->rules('required');

        

        return $form;
    }
}
